<?php

namespace App\Http\Controllers\Customer;

use App\Http\Models\Admin\File\FileContent;
use App\Http\Models\Admin\Sys\Contacts;
use App\Http\Responses\ResponseDto;
use App\Services\Admin\EMailService;
use App\Services\Admin\CommonService;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View;
use Thujohn\Rss\RssFacade;

class CommonController extends Controller
{

//    Commons
    public function __construct(CommonService $service){
        $this->service = $service;
    }

     public function  rss(){
         ob_clean();
         $feed = RssFacade::feed('2.0', 'UTF-8');

         $posts = $this->service->getLeastPost(20);
         $seo = $this->service->getSiteMsg();


         $feed->channel(array('title' =>  $seo['site_seo_title'], 'description' => $seo['site_seo_description'], 'link' => url(),'lastBuildDate'=>Carbon::now()));


         foreach ($posts as $post){
             $feed->item(array('title' => $post->title, 'description|cdata' => $post->post_content, 'link' =>  $post->href,'pubDate'=>$post->created_at));
         }

         return Response::make($feed, 200, array('Content-Type' => 'text/xml'));
     }
     public function  sitemap(){

         ob_clean();
         $sitemap = App::make("sitemap");
         $sitemap->setCache('cms.sitemap', 60);

         if (!$sitemap->isCached())
         {
             $commaps = $this->service->getSiteMapList();
             foreach ($commaps as $item)
             {
                 $sitemap->add(url($item->name), $item->modified, $item->priorite, $item->frenquency);
             }
         }
         return $sitemap->render('xml');
     }
}
